﻿using System;
using CommandLine;
using Crypton;

namespace GenKey
{
    class Program
    {
        static int Main(string[] args)
        {
            var options = new Options();
            var parserSettings = new CommandLineParserSettings(Console.Error);
            var parser = (ICommandLineParser)new CommandLineParser(parserSettings);
            var parseOk =  parser.ParseArguments(args, options);
            var result = parseOk ? 0 : 1;
            if(result == 0)
            {
                try
                {
                    ServiceFactory.CreateCryptonService().GenerateCryptoKey(options.AlgorithmName, 
                        options.KeyLength, options.Key);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    result = 1;
                }
            }
#if DEBUG
            Console.ReadLine();
#endif
            return result;
        }
    }
}
